package com.example.sd;

import android.app.Activity;
import android.content.pm.PackageManager;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class PermissionUtils {




    public static boolean checkPermission(Activity activity,String[] permissions,int requestCode){

        int check = PackageManager.PERMISSION_GRANTED;
        for (String permission : permissions) {
            check = ContextCompat.checkSelfPermission(activity, permission);
            if(check != PackageManager.PERMISSION_GRANTED){
                break;
            }
        }

        // 没有权限，申请权限
        if(check != PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(activity,permissions,requestCode);
            return false;
        }
        return true;
    }

    public static boolean checkGrantResults(int[] grantResults) {
        if(grantResults != null){
            for (int grantResult : grantResults) {
                if(grantResult != PackageManager.PERMISSION_GRANTED){
                    return false;
                }
            }
            return true;
        }
        return false;
    }
}
